using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace Bll
{
	class CLogManage
	{
		public static CLog CreateLog()
       {      
           return   new CLog();
       }
	   
	   public static CLog Save(CLog log)
	   {
			try
           {
				int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_AddLog", log.ID, log.title, log.logContent, log.type);
             
				if(0 == num)
                   return null;
                return log;
           }
           catch (Exception e)
           {
               return null;
           }
	   }
	   
	   public static bool Update(CLog log)
	   {
			try
			{
				int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_SaveLog", log.ID, log.title, log.logContent, log.type);
				if (0 == num)
                   return false;
				return true;
			}
			catch (Exception e)
			{
               return false;
			}
	   }
	   
	   public static bool Delete(CLog log)
	   {
			try
			{
				int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_RemoveLog", log.ID);
				if (0 == num)
                   return false;
				return true;
			}
			catch (Exception e)
			{
               return false;
			}
	   }
	   
	   static CLog GetLog(String ID)
	   {
			try
           {
               
               SqlDataReader reader= BLL.SqlHelper.ExecuteReader(CConnection.getConnString(), "sp_GetLog", ID);
               if (reader.NextResult())
               { 
					CLog log = new CLog();
					log.title = reader["title"].ToString();
					log.logContent = reader["logContent"].ToString();
					log.type = (int) reader["type"];
					
					reader.Close();
					return log;
               }
			   reader.Close();
               return null;
           }
           catch (Exception e)
           {

               //reader.Close();
               return null;
           }
	   }
	}
}